<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        .box {
            position: absolute;
            top:100px;
            left:0;
            width: 100px;
            height: 100px;
            background-color: pink;
        }
    </style>
</head>
<body>
<button id="btn">开始</button>
<div class="box" id="bOX">
</div>
</body>
</html>
<script>
    var btn = document.getElementById("btn");
    var box = document.getElementById("bOX");
    var num = 0;
    var timer = null;
    btn.onclick = function() {
        timer = setInterval(function(){
            num++;
            if(num >=500)
            {
                clearInterval(timer);
            }
            else
            {
                box.style.left = num + "px";
            }
        },10)
    }
</script>